Max's daily travel

Submitted as CSS 625 Assignment

Analyst: Talha OZ

Instructor: Maksim Tsvetovat


In [1]:
import pandas as pd
import numpy as np
from datetime import datetime
from geopy.distance import vincenty
%matplotlib inline
import plotly.plotly as py
from plotly.graph_objs import *

In [2]:
def get_dist(x):
    """
    sum distances on day x where latlon is a list of locations
    latlon[i] -> (latlon[0],latlon[1]), (latlon[1],latlon[2]), ...
    """
    dist = 0
    latlon = list(zip(x.lat.tolist(),x.lon.tolist()))
    for i in range(1,len(latlon)):
        dist += vincenty(latlon[i], latlon[i-1]).miles
    return dist

In [3]:
df = pd.read_json('openpaths_maksim2042.json')
df.t = df.t.apply(lambda x: datetime.fromtimestamp(x).date())

In [4]:
g = df.groupby(by='t')
dist = g.apply(lambda x: get_dist(x))
dist.plot()


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x109735780>

In [5]:
y,x = np.histogram(dist, bins=len(df)/50)
data = Data([Scatter(x=x,y=y)])
layout = Layout(
    title='Max\'s daily travel',
    xaxis=XAxis(type='log',autorange=True,title='Distance'),
    yaxis=YAxis(type='log',autorange=True,title='Frequency'))
fig = Figure(data=data, layout=layout)
py.iplot(fig, filename='Maxs daily travel')


Out[5]: